package com.skyolder.milkbee.mq;

import java.io.Serializable;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.apache.activemq.command.ActiveMQObjectMessage;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;

public class Converter implements MessageConverter {

	@Override
	public Instant fromMessage(Message message) throws JMSException, MessageConversionException {
		// TODO Auto-generated method stub
		Instant instant = null;  
        if(message instanceof ActiveMQObjectMessage){  
            ActiveMQObjectMessage aMsg = (ActiveMQObjectMessage) message;   
            instant=(Instant) aMsg.getObject();  
        }  
       return instant;  
	}

	@Override
	public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
		// TODO Auto-generated method stub
		
		//System.out.println("sendMessage:"+object.toString());    
        ActiveMQObjectMessage msg = (ActiveMQObjectMessage) session.createObjectMessage();  
        msg.setObject((Serializable) object);  
        return msg;   
	}  

}
